//
//  LoginViewController.m
//  NetWorkSave
//
//  Created by 苗旭萌 on 15/11/17.
//  Copyright © 2015年 苗旭萌. All rights reserved.
//

#import "LoginViewController.h"
#import <Parse/Parse.h>
#import "AppDelegate.h"
#import "ViewController.h"

@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passWordTextField;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (IBAction)LoginButtonClicked:(id)sender {

    [PFUser logInWithUsernameInBackground:self.nameTextField.text password:self.passWordTextField.text block:^(PFUser * _Nullable user, NSError * _Nullable error) {
        if (user) {
            AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
            
            ViewController *viewVC = [[ViewController alloc] init];
            UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:viewVC];
            
            app.window.rootViewController = navi;
            
            
            NSUserDefaults *userSince = [NSUserDefaults standardUserDefaults];
            
            [userSince setObject:self.nameTextField.text forKey:@"userName"];
            [userSince setObject:self.passWordTextField.text forKey:@"passWord"];
            
            [userSince setBool:YES forKey:@"isLogin"];
            [userSince setObject:@"userID" forKey:user.objectId];
        }else{
            NSLog(@"---------------------哈哈哈哈哈哈哈");
        }
        
        
        
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
